<template>
  <div class="main">
    <div class="order" ref="order">
        <div :class=" item.itemStyle " v-for="(item, index) in titleList" :key="index" @click="check(item, index)">{{ item.name }}</div>
    </div>
    <div class="content">
        <div class="title">{{ this.title }}</div>
        <div class="text" ref="text">{{ this.text }}</div>
    </div>
  </div>
</template>

<script>
import { getAll,getText } from '@/api/rules/rules';
export default {
    data(){
        return{
            title: '',
            text: '',
            titleList: [],
            query: '',
        }
    },
    methods: {
        check(item, index){
            this.text = [];
            this.title = item.name;
            for(let i in this.titleList){
                if(i == index){
                    this.titleList[i].itemStyle = 'itemSelected';
                }
                else{
                    this.titleList[i].itemStyle = 'item';
                }
            }
            console.log(item.id);
            getText(item.id).then((res) => {
                if(res){
                    this.text = res.data.nr;
                    this.$refs.text.innerHTML = this.text;
                    // console.log(this.$refs.text);
                }

            });
            
        },
        getList(){
            getAll().then((res) => {
                if(res){
                    this.titleList = res.data;
                    console.log('titleList',this.titleList);
                    for(let i of this.titleList){
                        i.itemStyle = 'item';
                    }
                    this.check(this.query, this.query.index);
                }
            })
        }
    },
    mounted(){
        this.getList();
        this.query = this.$route.query;
        console.log(window.screen.height);
        
    }
}
</script>

<style lang="less" scoped>
.main{
    display: flex;
    align-items: top;
    justify-content: center;
    background-color: rgb(250, 250, 250);
}
.main .order{
    background-color: rgb(240, 240, 240);
}
.item{
    padding: 12px 40px 11px 20px;
    text-align: left;
    color: #666;
    cursor: pointer;
}
.item:active{
    padding: 12px 40px 11px 20px;
    text-align: left;
    color: #fff;
    background-color: #3d40e5;
    cursor: pointer;
}
.itemSelected{
    padding: 12px 40px 11px 20px;
    text-align: left;
    color: #fff;
    background-color: #3d40e5;
    cursor: pointer;
}
.content{
    background-color: #fff;
    width: 70%;
}
.content .title{
    background-color: rgb(230, 230, 230);
    color: #222;
    // font-weight: bolder;
    padding: 10px 20px;
    font-size: 18px;
    text-align: left;
}

.content .text{
    padding-left: 10px;
}
</style>